package com.atguigu.stack.array;

import java.util.Scanner;

/**
 * @ClassName ArrayStackTest
 * @DeScription 数组栈测试类
 * @Author 剧情再美终是戏
 * @Date 2019/11/29 20:59
 * @Version 1.0
 **/
public class ArrayStackTest {

    public static void main(String[] args) {
        ArrayStack arrayStack = new ArrayStack(3);

        // 测试
        boolean flag = true;
        while (flag) {
            System.out.println("=====================================");
            System.out.println("s--->打印数据");
            System.out.println("p--->入栈");
            System.out.println("g--->出栈");
            System.out.println("e--->退出");
            System.out.println("=====================================");
            System.out.println("请输入:");

            Scanner scanner = new Scanner(System.in);
            char in = scanner.next().charAt(0);

            switch (in) {
                case 's':
                    arrayStack.show();
                    break;
                case 'p':
                    System.out.println("请输入一个值(数字):");
                    int val = scanner.nextInt();
                    arrayStack.push(val);
                    break;
                case 'g':
                    try {
                        int pull = arrayStack.pull();
                        System.out.println("出栈的内容是：" + pull);
                    } catch (Exception e) {
                        break;
                    }
                    break;
                case 'e':
                    flag = false;
                    scanner.close();
                    break;
                default:
                    break;
            }
        }
    }
}
